<?php
/**
 * 工作部分
 * 
 * @package ews
 * @ews Enterprise WorkShop
 * @version 1.0
 * @since 2011-06-25
 * @author monkee
 */

class todoModel extends model
{
	public function add($user_id, $subject, $message, $end_date, $state=0){
		$state=empty($state)?0:$state;
		$data = array(
			'user_id' => $user_id,
			'subject' => $subject,
			'message' => $message,
			'end_date' => $end_date,
			'state' => $state
		);
		return DB::insert('todo', $data);
	}
	
	public function get_todo($id){
		return DB::fetchOne('SELECT * FROM '.DB::table('todo').' WHERE todo_id = '.$id);
	}
	
	public function finish_todo($id){
		DB::update('todo', array('state' => 1), 'todo_id = '.$id);
	}
		
	public function delete_todo($id){
		DB::delete('todo', 'todo_id = '.$id);
	}
	
	public function get_finished_todos($user_id){
		return DB::fetchArray('SELECT * FROM '.DB::table('todo').' WHERE state = 1 AND user_id = '.$user_id.' ORDER BY todo_id DESC LIMIT 10');
	}
	
	public function get_unfinished_todos($user_id){
		return DB::fetchArray('SELECT * FROM '.DB::table('todo').' WHERE state = 0 AND user_id = '.$user_id);
	}
}
?>